import java.util.Date;
import java.lang.reflect.Field;
import java.lang.reflect.*;
 
public class GetSetFieldDemo {
    public static Date now;
    public Long id;
    public String name;

    public static void abc()
    {
        System.out.println(1);
    }
 
    public static void main(String[] args) {
        GetSetFieldDemo demo = new GetSetFieldDemo();
        Class clazz = demo.getClass();
 
        try {
            //
            // Get field id, set it value and read it back
            //
            Field field = clazz.getField("id");
            field.set(demo, new Long(10));
            Object value = field.get(demo);
            System.out.println("Value = " + value);
 
            //
            // Get static field date, set it value and read it back
            //
            field = clazz.getField("now");
            field.set(null, new Date());
            value = field.get(null);
            System.out.println("Value = " + value);

            Field[] fields = clazz.getFields();

            for(int i = 0;i<fields.length;i++) {
                System.out.println(fields[i].getName());
            }

            Method[] methods = clazz.getMethods();

            for(int i = 0;i<methods.length;i++){
                System.out.println(methods[i].getName());
            }
            
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
 
    }
}